package com.atguigu.study.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.qdrant.QdrantEmbeddingStore;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Marco
 * @Description
 * @date 2025/8/22 2:03
 * @email 3293336923@qq.com
 */
@Configuration
public class LLMConfig {


    @Bean
    public EmbeddingModel  embeddingModel(){

        return OpenAiEmbeddingModel.builder()
                .apiKey(System.getenv("ALIQW"))
//                向量模型
                .modelName("text-embedding-v3")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }

//    创建   Qdrant 客户端
    @Bean
    public QdrantClient   qdrantClient(){
        QdrantGrpcClient.Builder    grpcClientBuilder =
                QdrantGrpcClient.newBuilder("192.168.100.22" , 6334 , false) ;
        return  new QdrantClient(grpcClientBuilder.build());
    }

    @Bean
    public EmbeddingStore<TextSegment>   embeddingStore(){
        return QdrantEmbeddingStore.builder()
                .host("192.168.100.22")
                .port(6334)
                .collectionName("test-qdrant")
                .build();
    }

}
